<template>
  <div>
    <el-form ref="queryForm" :model="queryForm" :inline="true" size="mini">
      <!-- 顾客名称 -->
      <el-form-item label="顾客名称" prop="customerName">
        <el-select
          v-model="queryForm.customerName"
          filterable
          placeholder="请输入顾客名称"
          allow-create
          clearable
          default-first-option
          style="width: 8vw"
        >
        <el-option
          v-for="item in customerList"
          :key="item.id"
          :label="item.customerName"
          :value="item.customerName"
        >
        </el-option>
        </el-select>
      </el-form-item>

      <!-- 钢种 -->
      <el-form-item label="钢种" prop="steelGradeId">
        <el-select
          v-model="queryForm.steelGradeId"
          placeholder="请选择钢种"
          style="width: 8vw"
          default-first-option
          allow-create
          clearable
          filterable
        >
          <el-option
            v-for="item in steelGradeList"
            :key="item.id"
            :value="item.steelGradeName"
            :label="item.steelGradeName"
          />
        </el-select>
      </el-form-item>

      <!-- 审核类型 -->
      <el-form-item label="审核类型" prop="reviewType">
        <el-select
          v-model="queryForm.reviewType"
          placeholder="请选择审核类型"
          clearable
          style="width: 8vw"
        >
        <el-option v-for="item in reviewTypes" :key="item.id" :value="item.reviewType" :label="item.reviewType" />
        </el-select>
      </el-form-item>

      <!-- 钢类 -->
      <el-form-item label="钢类" prop="steelTypeId">
        <el-select
          v-model="queryForm.steelTypeId"
          placeholder="请选择钢类"
          clearable
          style="width: 8vw"
        >
        <el-option v-for="item in steelTypes" :key="item.id" :value="item.steelTypeName" :label="item.steelTypeName" />
        </el-select>
      </el-form-item>

      <!-- 提交日期 -->
      <el-form-item label="提交日期" prop="submitTime">
        <el-date-picker
          v-model="queryForm.submitTime"
          value-format="yyyy-MM-dd"
          type="date"
          placeholder="选择日期"
          style="width: 8vw"
        >
        </el-date-picker>
      </el-form-item>

      <!-- 编号 -->
      <el-form-item label="编号" prop="code">
        <el-input
          v-model="queryForm.code"
          placeholder="请输入编号"
          clearable
          style="width: 8vw"
        ></el-input>
      </el-form-item>

      <!-- 查询和重置按钮 -->
      <el-form-item style="margin-left: 10px">
        <el-button type="primary" size="small" @click="handleClick"
          >查询</el-button
        >
        <el-button type="success" size="small" @click="handleReset"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-card style="height: 100%">
      <div slot="header">待审核订单</div>
      <hmi-table
        :table-data="tableData"
        :table-head="true"
        :is-pagination-show="true"
        :table-height="'calc(100vh - 230px)'"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="total"
        index-type="index"
        @handle-size-change="handleSizeChange"
        @handle-current-change="handleCurrentChange"
      >
        <template slot="TableBody">
          <!-- 编号 -->
          <el-table-column prop="code" label="编号" width="100" align="center">
          </el-table-column>

          <!-- 审核类型 -->
          <el-table-column prop="reviewType" label="审核类型" align="center">
          </el-table-column>

          <!-- 顾客名称 -->
          <el-table-column prop="customerName" label="顾客名称" align="center">
          </el-table-column>

          <!-- 顾客联系方式 -->
          <el-table-column
            prop="customerPhone"
            label="顾客联系方式"
            width="180"
            align="center"
          >
          </el-table-column>

          <!-- 钢类 -->
          <el-table-column prop="steelTypeName" label="钢类" align="center">
            <template slot-scope="scope">
              {{ scope.row.steelTypeName }}
            </template>
          </el-table-column>

          <!-- 钢种 -->
          <el-table-column
            prop="steelGradeName"
            label="钢种"
            align="center"
            width="150"
          >
            <template slot-scope="scope">
              {{ scope.row.steelGradeName }}
            </template>
          </el-table-column>
          <!-- 标准 -->
          <el-table-column
            prop="standardName"
            label="标准"
            width="200"
            align="center"
          >
          </el-table-column>

          <!-- 规格 -->
          <el-table-column prop="specification" label="规格" align="center">
          </el-table-column>

          <!-- 数量 -->
          <el-table-column prop="steelNumber" label="数量" align="center">
            <template slot-scope="scope">
              {{ scope.row.steelNumber }}{{ scope.row.steelNumberUnit }}
            </template>
          </el-table-column>

          <!-- 交货状态 -->
          <el-table-column
            prop="deliveryStatus"
            label="交货状态"
            align="center"
          >
          </el-table-column>

          <!-- 加工用途 -->
          <el-table-column
            prop="processingPurpose"
            label="加工用途"
            align="center"
          >
          </el-table-column>

          <!-- 提交时间 -->
          <el-table-column
            prop="submitTime"
            label="提交时间"
            width="160"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{ formatterTime(scope.row.submitTime) }}</span>
            </template>
          </el-table-column>

          <!-- 操作 -->
          <el-table-column label="操作" width="70" align="center">
            <template slot-scope="scope">
              <el-button type="text" @click="handleEdit(scope.row)">处理</el-button>
            </template>
          </el-table-column>
        </template>
      </hmi-table>
    </el-card>
  </div>
</template>

<script>
import HmiTable from "@/components/HmiTable.vue";
import { timeChange } from "@/lib/FormatTime";
import {
  GET_STANDARD_PENDINGORDER,
  GET_STEELGRADELIST,
  GET_CUSTOMERNAMELIST,
  GET_STEELTYPELIST,
  GET_REVIEWTYPE
} from "@/lib/Api.js";
import { post, get } from "@/lib/Util.js";
export default {
  components: {
    HmiTable
  },
  data() {
    return {
      queryForm: {},
      pageSize: 20,
      total: 0,
      currentPage: 1,
      tableData: [],
      steelGradeList: [],
      customerList: [],
      steelTypes: [],
      reviewTypes: []
    };
  },
  mounted() {
    this.getSteelGradeName();
    this.getCustomerNames(); // 获取顾客
    this.getsteelTypeNames();
    this.getData(this.currentPage, this.pageSize);
    this.getreviewTypes();
  },
  methods: {
    formatterTime(time) {
      if (time !== "" && time !== undefined) {
        return timeChange(time);
      } else {
        return "";
      }
    },
    handleClick() {
      this.getData(this.currentPage, this.pageSize);
    },
    getData(page, num) {
      let data = Object.assign(this.queryForm, {
        current: page,
        page: num
      });
      post(GET_STANDARD_PENDINGORDER, data).then(resp => {
        const { total, rows } = resp;
        this.total = total;
        this.tableData = rows;
      });
    },
    handleReset() {
      this.$refs["queryForm"].resetFields();
      this.getData(this.currentPage, this.pageSize);
    },
    //显示条数改变
    handleSizeChange(num) {
      this.pageSize = num;
      this.getData(1, num);
    },
    // 页数改变
    handleCurrentChange(page) {
      this.currentPage = page;
      this.getData(page, this.pageSize);
    },
    handleEdit(row) {
      if (row.reviewType == "评审信息规范性") {
        this.$router.push({
          name: "standard-pendingOrderReview-informationStandardization",
          params: { id: row.id }
        });
      } else {
        // 调用 Vuex action 来更新共享参数
        this.$store.dispatch("updateShareId", row.id);
        this.$router.push({
          name: "standard-pendingOrderReview-informationCompliance"
        });
      }
    },
    // 获取顾客
    getCustomerNames() {
      post(GET_CUSTOMERNAMELIST, { customerName: "" }).then(resp => {
        this.customerList = resp.data;
      });
    },
    getSteelGradeName() {
      post(GET_STEELGRADELIST, { steelGradeName: "" }).then(resp => {
        this.steelGradeList = resp.data;
      });
    },
    getreviewTypes() {
      get(GET_REVIEWTYPE).then(resp => {
        this.reviewTypes = resp.data;
      });
    },
    // 获取钢类
    getsteelTypeNames() {
      post(GET_STEELTYPELIST, { steelTypeName: "" }).then(resp => {
        this.steelTypes = resp.data;
      });
    }
  }
};
</script>

<style scoped>
</style>
